package com.bestcem.xm.om.constant;

import com.bestcem.xm.common.core.uitls.DateUtil;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

/**
 * redis key常量
 *
 * @author zhangfeng <feng.zhang@idiaoyan.com>
 * @version v1.0
 * @date 2021/11/15 17:25
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class RedisKeyConstant {
    /**
     * 租户数据，历史数据定时任务时间
     */
    public static final String OM_STAT_TIME = "om:stat:time";

    /**
     * 租户数据，账号数总数
     */
    public static final String ORG_ACCOUNT_COUNT = "om:account:total:%s";

    /**
     * 租户数据，账号数当日新增
     */
    public static final String ORG_ACCOUNT_DAY_COUNT = "om:account:total:%s:%s";

    /**
     * 租户数据，问卷项目总数
     */
    public static final String ORG_PROJECT_COUNT = "om:project:total:%s";

    /**
     * 租户数据，问卷项目当日新增
     */
    public static final String ORG_PROJECT_DAY_COUNT = "om:project:total:%s:%s";

    /**
     * 租户数据，答卷数总数
     */
    public static final String ORG_RESPONDENT_COUNT = "om:org:respondent:total:%s";

    /**
     * 租户数据，答卷数当日新增
     */
    public static final String ORG_RESPONDENT_DAY_COUNT = "om:org:respondent:total:%s:%s";

    /**
     * 问卷项目，答卷数总数
     */
    public static final String QDES_RESPONDENT_COUNT = "om:qdes:respondent:total:%s";

    /**
     * 问卷项目，答卷数当日新增
     */
    public static final String QDES_RESPONDENT_DAY_COUNT = "om:qdes:respondent:total:%s:%s";

    /**
     * 数据统计，问卷项目定时任务时间
     */
    public static final String QDES_STAT_TIME = "om:qdes:time";

    /**
     * 数据统计，历史数据统计是否在进行中
     */
    public static final String STAT_HISTORY_RUN = "om:stat:history";

    /**
     * 数据统计，实时数据统计是否在进行中
     */
    public static final String STAT_PROJECT_CURRENT_RUN = "om:stat:project:current";

    /**
     * 通知中心，短信同步数据接口redisKey
     */
    public static final String OM_NOTICE_SMS_SYC = "om:notice:sms:syc";

    /**
     * 通知中心，唯一链接对应的key
     */
    public static final String OM_UNIQUE_LINK_VISITED_TIMES = "om:notice:ulink:%s";

    /**
     * 通知中心，处理批次加锁
     */
    public static final String OM_BATCH_HANDLE = "om:notice:batch:%s";

    /**
     * om每周自动取数发邮件
     */
    public static final String OM_WEEKLY_DATA_OM_STAT = "om:stat:weekly:om";

    /**
     * 通知中心，统计邮件批次已执行数量
     */
    public static final String OM_BATCH_MAIL_HANDLE = "om:notice:batch:%s:mail";

    /**
     * 通知中心，统计邮件批总数
     */
    public static final String OM_BATCH_MAIL_TOTAL = "om:notice:batch:%s:mail:total";

    /**
     * 传送门，授权信息
     */
    public static final String OM_DELIVERY_RECORD = "om:delivery:record:%s";

    /**
     * 传送门，处理记录加锁
     */
    public static final String OM_DELIVERY_HANDLE = "om:delivery:handle:%s";

    /**
     * OM登录，用户token版本
     */
    public static final String OM_TOKEN_VERSION = "om:user:token:version:%s";

    /**
     * 传送门token失效的前缀
     */
    public static final String OM_TOKEN_LOGOUT = "om:delivery:token:%s";

    /**
     * 传送门生成key的前缀
     */
    public static final String OM_DELIVERY_KEY = "om:delivery:%s";

    /**
     * 预约申请，接口调用频率控制key
     */
    public static final String WEILIN_CALL_COUNT = "xm:om:weilin:count";

    /**
     * 预约申请，初始化接口是否完成key
     */
    public static final String WEILIN_RUNNING = "xm:om:weilin:running";
    /**
     * 邮箱获取，初始化接口是否完成key
     */
    public static final String WEILIN_MAIL = "xm:om:weilin:email";

    /**
     * 预约申请，同步卫瓴数据需要加锁，防止高并发情况
     */
    public static final String WEILIN_CUSTOMER_KEY = "xm:om:weilin:customer:%s";

    /**
     * 预约申请，同步卫瓴数据需要加锁，防止高并发情况
     */
    public static final String WEILIN_CUSTOMER_FAIL_KEY = "xm:om:weilin:customer:fail:%s";

    /**
     * 日期key
     */
    private static final String KEY_DATE_PATTERN = "yyyyMMdd";

    /**
     * 倍市得合作伙伴招募短信验证码前缀
     */
    public static final String BOOKING_PHONE_VCODE_PREFIX = "OPENPLATFORM:BOOKING:%s";

    public static final String USER_PACK_PERM = "USER:pack_perm_%s";

    public static String getOrgAccountDayCountKey(String orgId) {
        String today = DateUtil.formatString(LocalDateTime.now(), KEY_DATE_PATTERN);
        return String.format(RedisKeyConstant.ORG_ACCOUNT_DAY_COUNT, today, orgId);
    }

    public static String getOrgAccountCountKey(String orgId) {
        return String.format(RedisKeyConstant.ORG_ACCOUNT_COUNT, orgId);
    }

    public static String getOrgProjectDayCountKey(String orgId) {
        String today = DateUtil.formatString(LocalDateTime.now(), KEY_DATE_PATTERN);
        return String.format(RedisKeyConstant.ORG_PROJECT_DAY_COUNT, today, orgId);
    }

    public static String getOrgProjectCountKey(String orgId) {
        return String.format(RedisKeyConstant.ORG_PROJECT_COUNT, orgId);
    }

    public static String getOrgRespondentDayCountKey(String orgId) {
        String today = DateUtil.formatString(LocalDateTime.now(), KEY_DATE_PATTERN);
        return String.format(RedisKeyConstant.ORG_RESPONDENT_DAY_COUNT, today, orgId);
    }

    public static String getOrgRespondentCountKey(String orgId) {
        return String.format(RedisKeyConstant.ORG_RESPONDENT_COUNT, orgId);
    }

    public static String getQdesRespondentDayCountKey(String projectId) {
        String today = DateUtil.formatString(LocalDateTime.now(), KEY_DATE_PATTERN);
        return String.format(RedisKeyConstant.QDES_RESPONDENT_DAY_COUNT, today, projectId);
    }

    public static String getQdesRespondentCountKey(String projectId) {
        return String.format(RedisKeyConstant.QDES_RESPONDENT_COUNT, projectId);
    }

    /**
     * 电脑端横幅广告
     */
    public static final String OM_AD_BANNER_COMPUTER_PREFIX = "xm:om:ad:banner:computer:";
    /**
     * 手机端横幅广告
     */
    public static final String OM_AD_BANNER_MOBILE_PREFIX = "xm:om:ad:banner:mobile:";
    /**
     * 登录页广告
     */
    public static final String OM_AD_LOGINPAGE_COMPUTER_PREFIX = "xm:om:ad:loginpage:computer:";

    /**
     * 广告刷新redisKey
     */
    public static final String OM_AD_REFRESH = "xm:om:ad:refresh";

    /**
     * 发票审核，真实租户通知设置缓存
     */
    public static final String INVOICE_EMAIL_CONF_REAL = "xm:om:invoice:conf:real";

    /**
     * 发票审核，内部测试租户通知设置缓存
     */
    public static final String INVOICE_EMAIL_CONF_TEST = "xm:om:invoice:conf:test";

    /**
     * 订单管理，真实租户通知设置缓存
     */
    public static final String ORDER_EMAIL_CONF_REAL = "xm:om:order:conf:real";

    /**
     * 订单管理，内部测试租户通知设置缓存
     */
    public static final String ORDER_EMAIL_CONF_TEST = "xm:om:order:conf:test";

    /**
     * 租户管理，导出并发控制
     */
    public static final String ORG_EXPORT_COUNT = "xm:om:org:export:count";

    /**
     * 租户管理，导出状态
     */
    public static final String ORG_EXPORT_STATUS = "xm:om:org:export:%s";

    /**
     * 套餐消费数据
     */
    public static final String USER_PACK_CONSUMPTION = "USER:pack_consumption_%s";

    public static String getConsumptionKey(String orgId) {
        return String.format(RedisKeyConstant.USER_PACK_CONSUMPTION, orgId);
    }

    /**
     * 代理充值手机验证码key
     */
    public static final String OM_AGENT_RECHARGE = "xm:om:wallet:agent_recharge_key:%s";

    /**
     * 销售邮箱，hash形式
     */
    public static final String SALE_KEY = "app:om:customer:event:email";

    /**
     * 敏感词审核记录更新key
     */
    public static final String SENSITIVE_WORD_OPERATE = "om:sensitive_word:operate:%s";
}
